def get_autocorrelation(sequence):
    n = len(sequence)
    autocorrelation = []
    for shift in range(n):
        sum = 0
        for i in range(n - shift):
            sum += sequence[i] * sequence[i + shift]
        autocorrelation.append(sum)
    return autocorrelation


def is_barker_code(autocorrelation):
    if max(autocorrelation[1:]) <= 1 and min(autocorrelation[1:]) >= -1:
        return True
    else:
        return False


def test_barker_codes():
    seqs = [[1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1, -1, 1]]
    for seq in seqs:
        autocorrelation = get_autocorrelation(seq)
        b = is_barker_code(autocorrelation)
        print("b=", b, "seq=", seq, "autocorrelation=", autocorrelation)


if __name__ == '__main__':
    test_barker_codes()
